package bit.client.model;

import java.util.List;

class Score{
    public String code;
    public String name;
    public String type;
    public float credit;
    public int score;

    Score(String _code, String _name, String _type, float _credit, int _score) {
        this.code = _code;
        this.name = _name;
        this.type = _type;
        this.credit = _credit;
        this.score = _score;
    }


    @Override
    public String toString() {
        String str = "name: " + name + " score: " + score + " credit: " + credit;
        return str;
    }


    public static float ave(List<Score> list){
        if(list.isEmpty()) return 0;
        float sum = 0;
        float creditSum = 0;
        for(Score score: list){
            creditSum += score.credit;
            sum += score.credit * score.score;
        }
        return sum / creditSum;
    }
}
